@extends('admin.layout.index')


@section('content')

    <!-- Content Header (Page header) -->
    <div class="content-header">
        <div class="container-fluid">


            <div class="card">
                <div class="card-header">
                    <h1 class="card-title">Добавить новую статью</h1>
                </div>
                <!-- /.card-header -->
                <div class="card-body">
                    <div class="row">
                        <div class="col-6">
                            <form method="post" action="{{route('posts.store')}}" enctype="multipart/form-data">
                                @csrf
                                <label for="name">Название статьи</label>
                                <input class="form-control form-control-lg" type="text" placeholder="Название статьи"
                                       name="name" id="name"/>


                                @if(count($categories) < 1)
                                    <div class="callout callout-warning mt-3">
                                        <h5>Нет ни одной категории для добавления</h5>
                                        <p><a href="{{route('categories.create')}}">Добавить категорию</a></p>
                                    </div>
                                @else
                                    <div class="form-group">
                                        <label for="category_id">Категория статьи</label>
                                        <select class="form-control" name="category_id" id="category_id">
                                            @foreach($categories as $key => $value)
                                                <option value="{{$key}}">{{$value}}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                @endif


                                @if(count($tags) < 1)
                                    <div class="callout callout-warning mt-3">
                                        <h5>Нет тегов для добавления</h5>
                                        <p><a href="{{route('tags.create')}}">Добавить теги</a></p>
                                    </div>
                                @else
                                    <div class="form-group" data-select2-id="29">
                                        <label style="min-width: 100%">
                                            <select name="tags[]" class="select2 select2-hidden-accessible" multiple=""
                                                    data-placeholder="Добавить теги" style="width: 100%;"
                                                    data-select2-id="7" tabindex="-1" aria-hidden="true">
                                                @foreach($tags as  $key => $value)
                                                    <option data-select2-id="{{$key}}" value="{{$key}}">{{$value}}</option>
                                                @endforeach
                                            </select>
                                        </label>
                                    </div>
                                @endif


                                <div class="form-group">
                                    <div class="input-group">
                                        <div class="custom-file">
                                            <input type="file" class="custom-file-input" id="image"  name="image">
                                            <label class="custom-file-label" for="image">Выбрать
                                                изображение</label>
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label for="description">Краткое описание</label>
                                    <textarea class="form-control" rows="2" placeholder="Описание статьи..."
                                              name="description" id="description"></textarea>
                                </div>

                                <div class="form-group">
                                    <label for="content">Текст статьи</label>
                                    <textarea class="form-control" rows="6" placeholder="Начните что то писать..."
                                              name="content" id="content"></textarea>
                                </div>


                                <button type="submit" class="btn btn-block btn-success btn-lg mt-3"
                                        style="width: 300px">Сохранить статью
                                </button>
                            </form>
                        </div>
                    </div>
                </div>
                <!-- /.card-body -->
            </div>

        </div>
    </div>

@endsection
<script src="http://mysite.local/adminlte/js/jquery.js"></script>
<!-- Bootstrap 4 -->
<script src="http://mysite.local/adminlte/js/bootstrap.js"></script>
<!-- AdminLTE App -->
<script src="http://mysite.local/adminlte/js/adminlte.js"></script>
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
<script>
    let activeLink = window.location.href;
    const menu = document.querySelectorAll('.nav-link');
    for (let i = 0; i < menu.length; i++) {
        console.log(menu[i])
        if (menu[i].href === activeLink) {
            menu[i].classList.add('active');
        }
    }
</script>
